package com.zhentao.equipment.controller;

import com.zhentao.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 配置ACK回执控制器：
 * 设备端配置更新后调用此接口回执版本号，用于服务端校验一致性。
 */
@RestController
@RequestMapping("/api/devices")
@CrossOrigin(origins = "*")
public class DeviceConfigAckController {

    @Autowired(required = false)
    private StringRedisTemplate redis;

    private String vKey(Long deviceId) { return "device:cfg:v:" + deviceId; }

    /**
     * 设备回执当前配置版本号
     */
    @PostMapping("/{id}/config-ack")
    public ResultVo ack(@PathVariable("id") Long deviceId, @RequestParam("version") String version) {
        if (redis == null) return ResultVo.error(400, "Redis未配置");
        redis.opsForValue().set(vKey(deviceId), version);
        return ResultVo.success();
    }
}





